package org.glut.wechat.personalcenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.glut.wechat.personalcenter.domain.LoginResult;
import org.glut.wechat.personalcenter.service.IUserService;
import org.glut.wechat.personalcenter.domain.User;
import org.glut.wechat.personalcenter.mapper.UserMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * 用户表 服务实现类
 *
 * @author bin
 * @since 2025-08-18 11:24
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public LoginResult passwordLogin(String phone, String password) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getPhone, phone);
        User user = this.getOne(queryWrapper);

        LoginResult result = new LoginResult();

        if (user == null) {
            result.setCode(1);
            result.setMsg("用户不存在");
            return result;
        }

        if (!password.equals(user.getPassword())) {
            result.setCode(2);
            result.setMsg("密码错误");
            return result;
        }

        result.setCode(0);
        result.setMsg("登录成功");
        result.setUser(user);
        return result;
    }
}
